import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: dings
 * Date: 2024-07-19
 * Time: 21:19
 */
public class Sort {
    public static void insertSort(int[] arr) {
        for (int i = 1; i < arr.length; i++) {
            int tmp = arr[i];
            for (int j = i-1; j >= 0; j--) {
                if (arr[j] > tmp) {
                    arr[j+1] = arr[j];
                }else {
                    arr[j+1] = tmp;
                    break;
                }
                if (j == 0) {
                    arr[0] = tmp;
                }
            }
        }
    }
    public static void main(String[] args) {
        int[] arr = {34,456,762,34,12,1,456,23};
        insertSort(arr);
        System.out.println(Arrays.toString(arr));
    }
}
